﻿using System;
using System.Collections.Generic;
using System.Linq;
using StructureMap;
using TimeTracker.Core.Domain;
using TimeTracker.Core.Domain.Entities;
using NHibernate.Linq;

namespace TimeTracker.Core.DataAccess.Implementation
{
    [Pluggable("Default")]
    public class UnosVremenaSatiRepository : RepositoryBase, IUnosVremenaSatiRepository
    {
        public IList<UnosVremenaSati> UzmiUnoseVremenaSateZaRadnikaPoId(int radnikId)
        {
            var satiRadnika = (from sati in NHibernateSession.Linq<UnosVremenaSati>()
                               where sati.UnosVremena.Radnik.RadnikId == radnikId
                               select sati).ToList();

            return satiRadnika;
        }

        public UnosVremenaSati UzmiUnosVremenaSatiPoRadnikIdZaDatum(int radnikId, DateTime dan)
        {
            var satiRadnikaZaDan = (from sati in NHibernateSession.Linq<UnosVremenaSati>()
                                    where
                                        sati.UnosVremena.Radnik.RadnikId == radnikId &&
                                        sati.UnosVremena.UnosVremenaDatum == dan
                                    select sati).FirstOrDefault();

            return satiRadnikaZaDan;
        }
    }
}